package com.project.poetry.service.controller;

import com.project.poetry.service.entity.dto.flyingflower.FlyingFlowerAnswerDTO;
import com.project.poetry.service.entity.dto.flyingflower.FlyingFlowerDTO;
import com.project.poetry.service.entity.dto.flyingflower.FlyingFlowerDetailDTO;
import com.project.poetry.service.entity.dto.flyingflower.FlyingFlowerRankingDTO;
import com.project.poetry.service.entity.po.flyingflower.FlyingFlowerPO;
import com.project.poetry.service.entity.po.user.UserPO;
import com.project.poetry.service.service.FlyingFlowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 飞花令控制器
 * @author mengxj
 */
@Api("飞花令")
@RestController
@RequestMapping("flyingFlower")
public class FlyingFlowerController {

    @Resource
    private FlyingFlowerService flyingFlowerService;

    @ApiOperation("根据关键字获取内容")
    @GetMapping("getContentByKeyWord")
    public FlyingFlowerDTO getContentByKeyWord(@RequestParam("keyWord") String keyWord,
                                               @RequestParam("flyingId") Long flyingId,
                                               @ApiIgnore UserPO user){
        return this.flyingFlowerService.getContentByKeyWord(keyWord, flyingId, user);
    }

    @ApiOperation("保存玩家输入的答案")
    @PostMapping("saveFlyingFlowerAnswer")
    public void saveFlyingFlowerAnswer(@RequestBody FlyingFlowerAnswerDTO flyingFlowerAnswer, @ApiIgnore UserPO user){
        this.flyingFlowerService.saveFlyingFlowerAnswer(flyingFlowerAnswer, user);
    }

    @ApiOperation("保存玩家游戏记录")
    @PutMapping("finish/{flyingId}")
    public void finish(@PathVariable("flyingId") Long flyingId, @ApiIgnore UserPO user){
        this.flyingFlowerService.finish(flyingId, user);
    }

    @ApiOperation("根据关键字查询游戏历史")
    @GetMapping("flyingFlowerHistory")
    public List<FlyingFlowerPO> flyingFlowerHistory(@RequestParam(value = "keyWord", required = false) String keyWord,
                                                    @RequestParam("status") Integer status,
                                                    @ApiIgnore UserPO user){
        return this.flyingFlowerService.flyingFlowerHistory(keyWord, status, user);
    }

    @ApiOperation("根据飞花令id查询答题过程详情")
    @GetMapping("flyingFlowerDetail/{flyingId}")
    public List<FlyingFlowerDetailDTO> flyingFlowerDetail(@PathVariable("flyingId") Long flyingId){
        return this.flyingFlowerService.flyingFlowerDetail(flyingId);
    }

    @ApiOperation("答题排行榜 前 num 名")
    @GetMapping("ranking/{num}")
    public List<FlyingFlowerRankingDTO> ranking(@PathVariable("num") Integer num){
        return this.flyingFlowerService.ranking(num);
    }
}
